package com.goldgov.information.service;

import java.io.IOException;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.select.Elements;
import com.goldgov.information.service.impl.ArticleRulesServiceImpl;
import com.goldgov.utils.BeanUtil;

/**
 * 爬虫模板
 * */
public class CrawlerTemplets{

	protected final Log logger = LogFactory.getLog(this.getClass());
	
	/**
	 * 根据类型运行相关的模板
	 * @throws IOException 
	 * */
	public CrawlerTemplets(CrawlerTempletEnum crawlerTempletEnum) throws IOException {
		logger.info("===========>开始执行爬虫自定义模板："+crawlerTempletEnum.getTempID());
		ArticleRules ar = BeanUtil.getBean(ArticleRulesServiceImpl.class).getArticleRulesByID(crawlerTempletEnum.getTempID());
		Document doc = Jsoup.connect(ar.getUrlAddress()).get();
		logger.info(doc.html());
		switch(crawlerTempletEnum) {
			case templet1:
				logger.info("templet1");
				break;
			case templet2:
				logger.info("templet2");
				break;
			case templet3:
				Elements ele=doc.select("ul[class=ul_title_list] li a");
				logger.info(ele);
				break;
		}
	}
}